#include <iostream>
using namespace std;
#include <unistd.h>
#include <string.h>

int main()
{
    pid_t id = fork();
    if (id < 0)
    {
        printf("errno: %d, errstring: %s\n",errno,strerror(errno));
        return errno;
    }
    else if(id == 0)
    {
        int cnt = 10;
        while(cnt--)
        {   
            printf("我是子进程，pid: %d\n",getpid());
            sleep(1);
        }
        exit(0);
    }
    else
    {
        
        while(1)
        {   
            printf("我是父进程，pid: %d\n",getpid());
            sleep(1);
        }
    }
    return 0;
}
